/**
 * Created by Administrator on 2017/5/22 0022.
 */
var person = JSON.parse(sessionStorage.getItem("person"));
console.log(person);
if (person==''||person==null) {
    alert('请先登录')
    window.location.href='denglu.html';
} else{
    var userId=person.userid;
    $.ajax({
        url: 'http://114.112.96.184:18080/auth/toStartup' ,
        type: 'get',
        data: {'userId':userId},
        async: false,
        success: function (data) {
            console.log(data);
            if(data.result < 0){
                window.location.href='cyzfw_renzheng.html';
            }
            if(data.result == 0){
                window.location.href='cyzfw_renzheng.html';
            }
            if (data.result == null) {
                window.location.href='cyzfw_renzheng.html';
            }

        },
        error: function (returndata) {

        }
    });

}

console.log(userId)
// 判断用户是否认证




$('#userId').val(userId);

$("#up").uploadPreview({ Img: "ImgPr", Width: 120, Height: 120 });
$("#form_test1").Validform({
    btnSubmit:".btn_next",
    beforeCheck:function(curform){
        var domains = '';
        $('input[name="areas"]:checked').each(function(){
            domains+=$(this).val()+','
        });
        domains=domains.substring(0,domains.length-1);
        $('#domain').val(domains)
    },
    beforeSubmit:function(curform){
        doUpload()
        return false;
    }


});

function doUpload() {
    var formData = new FormData($( "#form_test1" )[0]);
    console.log(formData)
    $.ajax({
        url: 'http://114.112.96.184:18080/startup/pb' ,
        type: 'POST',
        data: formData,
        async: false,
        cache: false,
        contentType: false,
        processData: false,
        success: function (data) {
            console.log(data);
            if (data.code=='000') {
                window.location.href='cyzfw_myProgress.html'
            }else{
                // $('div.Validform_info').text(data.msg)
                $('#myModal .modal-body').text(data.msg);
                $('#myModal').modal('show')
            }

        },
        error: function (returndata) {
            alert(returndata);
        }
    });
}

//		地区
$.ajax({
    type: "get",
    url:"http://114.112.96.184:18080/dict/area",
    async: false,
    error: function(request) {
        console.log("Connection error");
    },
    success: function(data) {
        console.log(data)
        var obj = data.result;
        var htmls='';
        for (var i = 0; i < obj.length;i++) {
            htmls+= "<option value=" + obj[i].id +" >"+ obj[i].value  +"</option>"
        }
        $('#area').html(htmls);
    }
});


//          项目阶段
$.ajax({
    type: "get",
    url:"http://114.112.96.184:18080/dict/startupStage",
    async: false,
    error: function(request) {
        console.log("Connection error");
    },
    success: function(data) {
        console.log(data)
        var obj = data.result;
        var htmls='';
        for (var i = 0; i < obj.length;i++) {
            htmls+= "<option value=" + obj[i].id +" >"+ obj[i].value  +"</option>"
        }
        $('#stageProject').html(htmls);
    }
});

//		领域
$.ajax({
    type: "get",
    url:"http://114.112.96.184:18080/dict/field",
    error: function(request) {
        console.log("Connection error");
    },
    success: function(data) {
        console.log(data)
        var obj = data.result;
        var htmls='';
        for (var i = 0; i < obj.length;i++) {

            htmls+= '<label class="checkbox-inline col-xs-3"><input type="checkbox" name="areas"  value="'+ obj[i].id +'">'+obj[i].value+'</label>'
        }
        $('#area_out').html(htmls);
    }
});

//	融资阶段
$.ajax({
    type: "get",
    url:"http://114.112.96.184:18080/dict/financingStage",
    async: false,
    error: function(request) {
        console.log("Connection error");
    },
    success: function(data) {
        console.log(data)
        var obj = data.result;
        var htmls='';
        for (var i = 0; i < obj.length;i++) {
            htmls+= "<option value=" + obj[i].id +" >"+ obj[i].value  +"</option>"
        }
        $('#financingStage').html(htmls);
    }
});


$('#pic,#book').on('change',function () {
    alert('已选择文件');
})